#include <iostream>
#include "WzSerialPort.h"
#include <cstring>
using namespace std;

WzSerialPort w;
void sendDemo()
{
	
	char buf[10];
	memset(buf, 0, 10);
	buf[0] = 0x02;
	buf[1] = 0x04;
	buf[2] = 0x00;
	buf[3] = 0x00;
	buf[4] = 0x00;
	buf[5] = 0x04;
	buf[6]= 0xF1;
	buf[7] = 0xFA;

	if (w.open("COM3", 9600, 0, 8, 1))
	{
		//for (int i = 0;i < 10;i++)
		{
			w.send(buf, 8);
		}
		cout << "send demo finished...";
	}
	else
	{
		cout << "open serial port failed...";
	}
}

void receiveDemo()
{
	//WzSerialPort w;
	//if (w.open("COM3", 9600, 0, 8, 1))
	{cout << "start receive...";

		char buf[1024];
	//	while (true)
		{
			memset(buf, 0,1024);
			w.receive(buf, 1024);
			cout << buf;
		}
	}
}

int main(int argumentCount, const char* argumentValues[]) 
{
	// 假设COM1已经和另外一个串口连接好了

	// 发送 demo
	sendDemo();

	// 接收 demo
	receiveDemo();

	getchar();
	return 0;
}